<template>
  <div class="app-container home">
    <el-card>
      <el-row :gutter="20">
        <el-col :span="24" style="text-align: center">
          <spn style="font-size: 30px; width: 100%">
            欢迎使用客户管理系统
          </spn>
        </el-col>
      </el-row>

      <el-row :gutter="20" style="margin-top: 70px;">
        <div ref="lineChart" style="width: 100%; height: 400px;"></div>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import {indexStatistics, lineChart} from "@/api";
import * as echarts from 'echarts';

export default {
  name: "Index",
  data() {
    return {
      // 统计数据
      statistics: {
        productCount: 0,
        subjectCount: 0,
        memberCount: 0,
        browseCount: 0,
        shareCount: 0
      },
      lineChart: null,
      lineDates: [],
      lineData: []
    };
  },
  created() {
    /*this.indexStatistics()
    this.indexChartLineData()*/
  },
  mounted() {

  },
  methods: {
    // 统计
    indexStatistics(){
      indexStatistics().then(response => {
        this.statistics = response.data;
      })
    },
    // 线形图
    initLineChart() {
      this.lineChart = echarts.init(this.$refs.lineChart);

      this.lineChart.setOption({
          title: {
            text: '近十日注册用户趋势图',
            left: 'center'
          },
          xAxis: {
            type: 'category',
            data: this.lineDates
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: this.lineData,
              type: 'line',
              smooth: true
            }
          ]
        })
    },
    // 线形图数据
    indexChartLineData() {
      lineChart().then(response => {
        for (let element in response.data) {
          this.lineDates.push(response.data[element].date)
          this.lineData.push(response.data[element].count)
        }

        this.initLineChart()
      })
    }
  }
};
</script>
